package com.wuhao.springbootactivemq.queue;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import java.util.UUID;

/**
 * @author: wuhao
 * @since: 2021/11/7 17:24
 */
@Component
@Slf4j
public class QueueProduct {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;

    @Scheduled(fixedDelay = 10000)
    public void productQueue() {
        String message = UUID.randomUUID().toString().substring(0, 5);
        jmsMessagingTemplate.convertAndSend(queue, "-------" + message);
        log.info("-------发送Message:{}", message);
    }
}
